/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package socafeclient;

import entity.Mesas;
import entity.Recetasinsumos;
import entity.Usuarios;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import javax.swing.table.AbstractTableModel;

/**
 *
 * @author alberto
 */
public class TableModelIngredientes extends AbstractTableModel{
    private ArrayList datalist = new ArrayList();
    private String[] columns = {"Idinsumo", "Nombre", "Cantidad", "TipoMedida"};
    

    @Override
    public int getRowCount() {
        return datalist.size();
    }

    @Override
    public int getColumnCount() {
        return columns.length;
    }

    @Override
    public Object getValueAt(int row, int col) {
       Recetasinsumos ri = (Recetasinsumos) datalist.get(row);        
       switch (col) {
            case 0: //idInsumo
                return ri.getInsumos().getIdinsumo();
            case 1: //Nombre
                return ri.getInsumos().getNombre();
            case 2: //Cantidad
                return ri.getCantidad();
            case 3: //TipoMedida                
                return ri.getInsumos().getTipomedida();            
            default:
                return false;
       }
               
    }

    public Recetasinsumos getRecetasinsumosAt(int row) {
        return (Recetasinsumos) datalist.get(row);
    }

    public Recetasinsumos removeRecetasinsumosAt(int row) {
        Recetasinsumos cp = (Recetasinsumos) datalist.remove(row);
        fireTableDataChanged();
        return cp;
        
    }

    public void addRecetasinsumos(Recetasinsumos c) {
        datalist.add(c);
        fireTableDataChanged();
    }

    public void addRecetasinsumosList(List l, boolean limpiar) {
        if (limpiar) {
            datalist.clear();           
        }        
        
        Iterator iterador = l.listIterator();        
        
        while(iterador.hasNext()){
            Recetasinsumos c = (Recetasinsumos) iterador.next();                                          
            datalist.add(c);            
        }        
        
        fireTableDataChanged();
    }

    public TableModelIngredientes(List l) {
        Iterator iterador = l.listIterator();        
        while(iterador.hasNext()){
             Recetasinsumos ri = (Recetasinsumos) iterador.next();
            datalist.add(ri);
        }        
    }

    public TableModelIngredientes() {
    }
    
    
    @Override
    public String getColumnName(int i) {
        return columns[i];
    }

    @Override
    public boolean isCellEditable(int row, int col) {
        switch (col) {
            case 0: //idInsumo
                return false;
            case 1: //Nombre
                return false;
            case 2: //Cantidad
                return false;
            case 3: //TipoMedida
                return false;            
            default:
                return false;
        }
    }

    @Override
    public Class getColumnClass(int col) {
        switch (col) {
            case 0: //idInsumo
                return Integer.class;
            case 1: //Nombre
                return Mesas.class;
            case 2: //Cantidad
                return Usuarios.class;
            case 3: //TipoMedida
                return Integer.class;            
            default:
                return null;
        }
    }

    
}

